import java.util.LinkedList;
import java.util.List;

/**
 * There are three types of containers. Each type has its own way for loading
 * and unloading goods. A container has a capacity depicting the allowed loading
 * weight.
 * 
 * @author Xi
 * 
 */
public abstract class Container {
	protected int capacity;
	protected int weight; // the total weight of goods in the container
	protected List<Goods> goodsList; // goods list

	public Container(int capacity) {
		this.capacity = capacity;
		goodsList = new LinkedList<Goods>(); // efficient for inserting and
												// deleting goods
	}

	public int getCapacity() {
		return capacity;
	}

	public void setCapacity(int capacity) {
		this.capacity = capacity;
	}

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}

	public List<Goods> getGoodsList() {
		return goodsList;
	}

	public void setGoodsList(List<Goods> goodsList) {
		this.goodsList = goodsList;
	}

	/**
	 * Load the given goods into the container.
	 * 
	 * @param goods
	 *            goods that will be loaded
	 */
	public abstract void load(Goods goods);

	/**
	 * Unload one goods from the container.
	 */
	public abstract void unload();

	public void loadGoods(Goods goods) throws TransportException {
		if ((weight + goods.getWeight()) <= capacity) {
			goodsList.add(goods); // insert new goods into the container
			weight += goods.getWeight(); // change the container weight
			System.out.println("The goods is loaded, goods weight: "
					+ goods.getWeight() + " , goods type: " + goods.getType()
					+ " , goods value: " + goods.getValue());
		} else {
			throw new TransportException(
					"The goods can not be loaded, because the container is already full!");
		}

	}

}
